<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>访问第二个p元素可以是以下代码</title>
</head>

<body>
    <h2>JavaScript HTML DOM!</h2>
    <p>Hello World!</p>
    <p>Hello Runoob!</p>
    <p id="demo"></p>
    <script>
        var myNodelist = document.querySelectorAll("p");
        document.getElementById("demo").innerHTML = "第二个段落的内容为:<span style='color:red;'> " + myNodelist[1].innerHTML + '</span>';
    </script>
</body>

</html>